﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using rock.DAL;
using rock.Model;
using System.Data.SqlClient;
using rock.UI.common;

namespace rock.UI.pictureinfo
{
    public partial class Form1HouseDetailInfo : Form
    {


        private int CONTRACT_SEQID = 0;
        public int _CONTRACT_SEQID { get { return CONTRACT_SEQID; } set { CONTRACT_SEQID = value; } }

        private int ROOM_SEQID = 0;
        public int _ROOM_SEQID { get { return ROOM_SEQID; } set { ROOM_SEQID = value; } }

        private int CUSTOM_SEQID = 0;
        public int _CUSTOM_SEQID { get { return CUSTOM_SEQID; } set { CUSTOM_SEQID = value; } }

       
        public Form1HouseDetailInfo()
        {
            InitializeComponent();
 
            this.MaximizeBox = false;
            this.MinimizeBox = false;
            this.WindowState = FormWindowState.Normal;
            this.StartPosition = FormStartPosition.CenterScreen;
            this.FormBorderStyle = System.Windows.Forms.FormBorderStyle.FixedSingle;
            this.Icon = global::rock.Properties.Resources.house;
            
        }

        private void Form1HouseDetailInfo_Load(object sender, EventArgs e)
        {

            if (this._ROOM_SEQID > 0)
            {
                

                this.userControlImportRoomInfo1._ROOM_SEQID = this._ROOM_SEQID;
                this.userControlImportRoomInfo1.inits(this._ROOM_SEQID);
                this.userControlImportRoomInfo1._SHOW_BUTTON = false;
            }
            else {
                MessageBox.Show("没有找到相关信息", "提示");
                return;
            }


          DataSet statusDs =   DbHelperSQL.Query(String.Format("SELECT  SEQID ,RENT_CUSTOM_SEQID , HOUSE_ROOM_SEQID FROM RENT_CONTRACT WHERE STATUS = 1 AND HOUSE_ROOM_SEQID = {0}",this._ROOM_SEQID));
          if (statusDs != null && statusDs.Tables.Count > 0 && statusDs.Tables[0].Rows.Count > 0)
          {
              this._CONTRACT_SEQID =(int)statusDs.Tables[0].Rows[0]["SEQID"];
              this._CUSTOM_SEQID =(int)statusDs.Tables[0].Rows[0]["RENT_CUSTOM_SEQID"];

            

            if (this._CONTRACT_SEQID>0)
            {
                //合同信息
                this.userControlImportRentContractInfo1._ROOM_SEQID = this._ROOM_SEQID;
                this.userControlImportRentContractInfo1._CONTRACT_SEQID = this._CONTRACT_SEQID;
                this.userControlImportRentContractInfo1._CUSTOM_SEQID = this._CUSTOM_SEQID;
                this.userControlImportRentContractInfo1.inits(_CONTRACT_SEQID, _ROOM_SEQID, _CUSTOM_SEQID);
                this.userControlImportRentContractInfo1._SHOW_BUTTON = false;

                //客户信息
                this.userControlImportCustomInfo1._CUSTOM_SEQID = this._CUSTOM_SEQID;
                this.userControlImportCustomInfo1.inits(_CUSTOM_SEQID);
                this.userControlImportCustomInfo1._SHOW_BUTTON = false;



    
                //押金
              
                SqlParameter[] Yparameters = {
                    new SqlParameter("@CONTRACT_SEQID", SqlDbType.Int, 4)
                                        };
                Yparameters[0].Value = _CONTRACT_SEQID;
                DataSet Yds = DbHelperSQL.RunProcedure("HOUSE_ROOM_DETAIL_YAJING", Yparameters, "ds");
                this.dataGridViewY.DataSource = Yds.Tables[0]; 
                //租金
                SqlParameter[] Zparameters = {
                    new SqlParameter("@CONTRACT_SEQID", SqlDbType.Int, 4)
                                        };
                Zparameters[0].Value = _CONTRACT_SEQID;
                DataSet Zds = DbHelperSQL.RunProcedure("HOUSE_ROOM_DETAIL_ZHUJING", Zparameters, "ds");
                this.dataGridViewZ.DataSource = Zds.Tables[0]; 
                //杂费
                SqlParameter[] Odparameters = {
                    new SqlParameter("@CONTRACT_SEQID", SqlDbType.Int, 4)
                                        };
                Odparameters[0].Value = _CONTRACT_SEQID;
                DataSet Ods = DbHelperSQL.RunProcedure("HOUSE_ROOM_DETAIL_OTHERFEE", Odparameters, "ds");
                this.dataGridViewO.DataSource = Ods.Tables[0]; 
            }

            
          }
        }

      


        private void dataGridViewY_RowPostPaint(object sender, DataGridViewRowPostPaintEventArgs e)
        {
            foreach (DataGridViewRow row in dataGridViewY.Rows)
            {
                row.Cells[0].Value = row.Index + 1;
            }
        }

        private void dataGridViewZ_RowPostPaint(object sender, DataGridViewRowPostPaintEventArgs e)
        {
            foreach (DataGridViewRow row in dataGridViewZ.Rows)
            {
                row.Cells[0].Value = row.Index + 1;
            }
        }

        private void dataGridViewO_RowPostPaint(object sender, DataGridViewRowPostPaintEventArgs e)
        {
            foreach (DataGridViewRow row in dataGridViewO.Rows)
            {
                row.Cells[0].Value = row.Index + 1;
            }
        }

        private void dataGridViewY_DataBindingComplete(object sender, DataGridViewBindingCompleteEventArgs e)
        {
            setYStatusWithDataGrid(dataGridViewY);
        }
        public void setYStatusWithDataGrid(DataGridView dgv)
        {
            for (int a = 0; a < dgv.Rows.Count; a++)
            {

                try
                {

                    int status = (int)dgv.Rows[a].Cells["STATUS"].Value;

                    DataGridViewTextBoxCell dgvcc = (DataGridViewTextBoxCell)dgv.Rows[a].Cells["STATUS_STR"];
                    dgvcc.Value = Constant.getByYajingStatus(status).Name;
                }
                catch (Exception)
                {

                }
            }
        }

        private void dataGridViewZ_DataBindingComplete(object sender, DataGridViewBindingCompleteEventArgs e)
        {

            setZStatusWithDataGrid(dataGridViewZ);
        }
        public void setZStatusWithDataGrid(DataGridView dgv)
        {
            for (int a = 0; a < dgv.Rows.Count; a++)
            {

                try
                {

                    int status = (int)dgv.Rows[a].Cells["ROOM_STATUS"].Value;

                    DataGridViewTextBoxCell dgvcc = (DataGridViewTextBoxCell)dgv.Rows[a].Cells["ROOM_STATUS_STR"];
                    dgvcc.Value = Constant.getByFeeStatus(status).Name;
                }
                catch (Exception)
                {

                }
            }
        }

        private void dataGridViewO_DataBindingComplete(object sender, DataGridViewBindingCompleteEventArgs e)
        {

            setOStatusWithDataGrid(dataGridViewO);
        }
        public void setOStatusWithDataGrid(DataGridView dgv)
        {
            for (int a = 0; a < dgv.Rows.Count; a++)
            {

                try
                {

                    int status = (int)dgv.Rows[a].Cells["OTHER_STATUS"].Value;
                    DataGridViewTextBoxCell dgvcc = (DataGridViewTextBoxCell)dgv.Rows[a].Cells["OTHER_STATUS_STR"];
                    dgvcc.Value = Constant.getByFeeStatus(status).Name;

                    int model = (int)dgv.Rows[a].Cells["FEE_MODEL"].Value;
                    DataGridViewTextBoxCell dgvccm = (DataGridViewTextBoxCell)dgv.Rows[a].Cells["FEE_MODEL_STR"];
                    dgvccm.Value = Constant.getByFeeTypeStatus(model).Name;
                }
                catch (Exception)
                {

                }
            }
        }

    }
}
